//
//  Reg2ViewController.m
//  FruitsWholesaler
//
//  Created by sgone-2 on 15/12/6.
//  Copyright © 2015年 sgone. All rights reserved.
//

#import "Reg2ViewController.h"
#import "AFNetworking.h"
#import "MBProgressHUD+MJ.h"
#import "Reg3ViewController.h"
#import "TransRuleViewController.h"


//添加地址区域
#import "HZAreaPickerView.h"
#import "MBProgressHUD+MJ.h"


////地址解析
#import <CoreLocation/CoreLocation.h>

//地址解析
#import <AMapSearchKit/AMapSearchKit.h>



@interface Reg2ViewController ()<UITextFieldDelegate,UITableViewDataSource,UITableViewDelegate,UIPickerViewDelegate,UIPickerViewDataSource,HZAreaPickerDelegate,AMapSearchDelegate>
//网路请求
@property(nonatomic,strong)AFHTTPSessionManager *manager;



@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property(nonatomic,strong) UITextField *textName;
@property(nonatomic,strong) UITextField *textPhone;
@property(nonatomic,strong) UITextField *textDQ;
@property(nonatomic,strong) UITextField *textSC;
@property(nonatomic,strong) UITextField *textDZ;
@property(nonatomic,strong) UITextField *textSHFW;
@property(nonatomic,strong) UITextField *textQSJG;
@property(nonatomic,strong) UITextField *textYFGZ;
@property(nonatomic,strong) UIButton *next;



//记录设置textfield的字符串
@property(nonatomic,strong) NSString *textName1;
@property(nonatomic,strong) NSString *textPhone1;
@property(nonatomic,strong) NSString *textDQ1;
@property(nonatomic,strong) NSString *textSC1;
@property(nonatomic,strong) NSString *textDZ1;
@property(nonatomic,strong) NSString *textSHFW1;
@property(nonatomic,strong) NSString *textQSJG1;
@property(nonatomic,strong) NSString *textYFGZ1;
@property(nonatomic,strong) UILabel *lblp;


//@property(nonatomic,strong) UIPickerView *pickView1;

//区域批发商地址pickView
@property(nonatomic,strong) UIPickerView *pickView2;
@property(nonatomic,strong) UIView *pick2View;


@property (strong,nonatomic) HZAreaPickerView *locatePicker;
//添加城市pickView蒙版
@property (strong,nonatomic) UIView *orderMskView2;



//获取得到省市
@property (nonatomic,strong)NSString *stateValue;
@property (strong,nonatomic)NSString *cityValue;
@property (strong,nonatomic)NSString *districtValue;;

//省市区拼接起来
@property(nonatomic,strong) NSString *areaValue;




//添加数字键盘模板
@property(nonatomic,strong) UIView *numberView;


//获取批发商信息list
@property(nonatomic,strong) NSMutableArray *list;
@property(nonatomic) NSInteger currentSelectInCom0;



//block从下一个页面传递回来的数据
//创建一个数组接收从下一个页面返回来的数值
@property(nonatomic,strong) NSArray *backArray;





//地图正向地理编码
@property(nonatomic,strong) AMapSearchAPI *search;
@property(nonatomic,strong) AMapGeocodeSearchRequest *geo;




@end

@implementation Reg2ViewController

{
     HZAreaPickerView *_locatePicker;
}


//afnetworking网络请求数据
- (AFHTTPSessionManager *)manager
{
    if (_manager == nil) {
        _manager  = [AFHTTPSessionManager manager];
    }
    return _manager;
    
    
}



-(void)back:(id)sender
{

    [self dismissViewControllerAnimated:YES completion:nil];

}

-(void)viewWillAppear:(BOOL)animated
{
    
    
    
   
}



- (void)viewDidLoad {
    [super viewDidLoad];
    self.titleLabel.text = @"注  册";
    self.titleLabel.font = [UIFont boldSystemFontOfSize:19];

    self.backBtn.hidden = NO;
    
    self.list = [NSMutableArray arrayWithCapacity:0];
    self.currentSelectInCom0 = 0;
    self.view.backgroundColor = BACKGROUND1;
    //配置用户Key
    [AMapSearchServices sharedServices].apiKey = gaodeSecrect;
    //初始化对象
    self.search = [[AMapSearchAPI alloc]init];
    self.search.delegate = self;
    //构造AMapGeocodeSearchRequest对象，address为必选项，city为可选项
    self.geo = [[AMapGeocodeSearchRequest alloc] init];

    
    
    
    
    
    

    
    
    
    
    //注册通知进行页面刷新
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shuaxin) name:@"shuaxian" object:nil];
    
    if (ViewHeight == 480.0) {
        
        
        self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 100, 0) ;
        
        
    }
    
    
    
    


}


//进行全局刷新
-(void)shuaxin
{


    
    self.textYFGZ.placeholder = @"已设置";
    [self.tableView reloadData];
 
//    NSIndexPath *te=[NSIndexPath indexPathForRow:7 inSection:0];//刷新第一个section的第7行
//    
//    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:te,nil] withRowAnimation:UITableViewRowAnimationMiddle];
    
    
    

}






-(void)sendAPI
{
    
    
 


   //获取市场批发商
    NSString *urlStr = [NSString stringWithFormat:@"%@get_market",SERVER_ADDRESS];
    NSDictionary *parmas = @{@"parent_id" : self.cityValue};
    
    [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
    [self.manager POST:urlStr parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        if ([responseObject[@"error_flag"] intValue] == 0) {
            
            NSArray *array = responseObject [@"data"];
       
            if (array.count == 0) {
                
                [self.view makeToast:@"暂未获得该地区的市场信息"];
                
            }
            else
            {
            
                self.list = [NSMutableArray arrayWithArray:array];
                
            
                //获得数据进行赋操作
                
                if (self.pick2View == nil) {
                    self.pick2View = [[UIView alloc]initWithFrame:CGRectMake(0, 64, ViewWidth, ViewHeight-64)];
                  
                    self.pick2View.backgroundColor = [UIColor clearColor];
                    [self.view addSubview:self.pick2View];

                }
                if (self.pickView2 == nil) {
                    self.pickView2 = [[UIPickerView alloc]initWithFrame:CGRectMake(0, ViewHeight *0.65, ViewWidth, ViewHeight *0.35)];
                    self.pickView2.backgroundColor = [UIColor whiteColor];
                    self.pickView2.delegate = self;
                    self.pickView2.dataSource = self;
                    [self.pick2View addSubview:self.pickView2];
                }
            //进行刷新所有的数据
                [self.pickView2 reloadAllComponents];
                self.pick2View.hidden = NO;
                self.pickView2.hidden = NO;
                
                //给蒙版添加手势进行去除手势
                //点击空白收回键盘
                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Tapped4:)];
                [self.pick2View addGestureRecognizer:tap];
            }
            
            [MBProgressHUD hideAllHUDsForView:self.tableView animated:YES];

            [self.tableView reloadData];
            
            
        }
        else
        {
        
            
            [MBProgressHUD hideAllHUDsForView:self.tableView animated:YES];
            NSString *str = [NSString stringWithFormat:@"%@",[responseObject objectForKey:@"result_msg"]];
            UIAlertView *alter =[[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [alter show];
 
        
        
        }
        
        
        
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        [MBProgressHUD hideAllHUDsForView:self.tableView animated:YES];
        UIAlertView *alter = [[UIAlertView alloc]initWithTitle:@"提示" message:@"连接网络失败" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alter show];
        
        
        
    }];
    



   

}


#pragma mark 手势进行操作去除蒙版
-(void)Tapped4:(id)sender
{


    //伸缩表格
    [UIView animateWithDuration:0.25 animations:^{
        if (self.view.y == -140) {
            self.view.y = 0;
            
            
        }
    }completion:^(BOOL finished){
        
        
    }];


    self.pickView2.hidden = YES;
    self.pick2View.hidden = YES;
    
    
    



}



-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{


    return 1;
    

}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{


    return 8;

}


-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{

    return 100;


}



-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    
    return  80;


}


-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 10)];
    view1.backgroundColor = BACKGROUND1;
    [self.view addSubview:view1];
    
    //添加图片
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 35, ViewWidth-20, 38)];
    imageView.image = [UIImage imageNamed:@"register_2"];
    [view1 addSubview:imageView];
    
    return view1;


}


-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{


    UIView *view10 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 10)];
    
//    [self.view addSubview:view10];
    
    
    self.next = [[UIButton alloc]initWithFrame:CGRectMake(20, 20, ViewWidth-40, 46)];
    [self.next.layer setMasksToBounds:YES];
    [self.next.layer setCornerRadius:3.0];
    [self.next setTitle:@"下一步" forState:UIControlStateNormal];
    [self.next setTitleColor:BenSe_COLOR forState:UIControlStateNormal];
    self.next.backgroundColor = [UIColor whiteColor];
    [view10 addSubview:self.next];
    
    [self.next addTarget:self action:@selector(next:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
    return view10;


}

#pragma MARK 跳转到下一个页面
-(void) next:(id)sender
{

    
    

    if (self.cityValue.length == 0 || self.textDZ.text.length == 0) {
        
        [self.view makeToast:@"请完善地址信息"];
        return;
        
        
    }
    
    
    if (self.textName.text.length == 0) {
        
        [self.view makeToast:@"请填写商户名称"];
        return;
        
    }
    if (self.textPhone.text.length == 0) {
        [self.view makeToast:@"请填写商户电话"];
        return;
    }
    
    if (self.textDQ.text.length == 0) {
        [self.view makeToast:@"请填写批发商地区"];
        return;
    }
    if (self.textSC.text.length == 0) {
        [self.view makeToast:@"请填写所属市场"];
        return;
    }
    if (self.textDZ.text.length == 0) {
        [self.view makeToast:@"请完善地址"];
        return;
    }
    if (self.textSHFW.text.length == 0) {
        [self.view makeToast:@"请完善送货范围"];
        return;
    }
    if (self.textQSJG.text.length == 0) {
        [self.view makeToast:@"请完善起送价格"];
        return;
    }
    if ([self.textYFGZ.placeholder isEqualToString:@"未设置"]) {
        
        [self.view makeToast:@"运费规则未设置"];
        return;
    }
    
    if (self.backArray.count == 0) {
        
        [self.view makeToast:@"运费规则未设置"];
        return;
        
    }
    

//    自带地图解析，经纬度不准确
    //根据地址解析经纬度
    
    
    //由市区和详细地址组成的数据传递进行名字解析获取得到经纬度
    NSString *adddress = [NSString stringWithFormat:@"%@%@",self.cityValue,self.textDZ.text];

    
    //高德获取经纬度
    self.geo.address = adddress;
    //发起正向地理编码
    [self.search AMapGeocodeSearch:self.geo];
    
    
    
    
//自带经纬度不精准
//    CLGeocoder *myGeocoder = [[CLGeocoder alloc]init];
//    [myGeocoder geocodeAddressString:adddress completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
//       
//        if ([placemarks count] > 0 && error == nil) {
//            
//            NSLog(@"Found %lu placemark(s)",(unsigned long)[placemarks count]);
//            CLPlacemark *firstPlacemark = [placemarks objectAtIndex:0];
//            NSLog(@"longitude = %f",firstPlacemark.location.coordinate.longitude);
//            NSLog(@"Latitude = %f",firstPlacemark.location.coordinate.latitude);
//            
//            
//            //海拔经纬度保存
//            self.dataHandler.latitude = [NSString stringWithFormat:@"%f",firstPlacemark.location.coordinate.latitude];
//            self.dataHandler.longtitude = [NSString stringWithFormat:@"%f",firstPlacemark.location.coordinate.longitude];
//            
////            longitude = 121.491832
////             Latitude = 31.260970
//            
//            
//        }
//        else if ([placemarks count] == 0 && error == nil)
//        {
//        
//            [self.view makeToast:@"解析不到地址,重新解析"];
//            return ;
//        
//        }
//        else if (error != nil)
//        {
//            NSLog(@"An error occurred = %@",error);
//            NSString *error1 = [NSString stringWithFormat:@"%@",error];
//            [self.view makeToast:error1];
//        
//            return;
//        }
//        else
//        {
//            [self.view makeToast:@"解析不到地址,重新解析"];
//            return ;
//        
//        
//        }
//        
//    }];
//    
    
    
    
    



}



//实现正向地理编码的回调函数
- (void)onGeocodeSearchDone:(AMapGeocodeSearchRequest *)request response:(AMapGeocodeSearchResponse *)response
{
    if(response.geocodes.count == 0)
    {
        
        [self.view makeToast:@"解析不到地址,重新输入"];
        return;
    }
    //通过AMapGeocodeSearchResponse对象处理搜索结果
    NSString *strCount = [NSString stringWithFormat:@"count: %d", response.count];
    NSString *strGeocodes = @"";
    for (AMapTip *p in response.geocodes) {
        strGeocodes = [NSString stringWithFormat:@"%@\ngeocode: %@", strGeocodes, p.description];
        //获得经纬度进行保存到本地
        self.dataHandler.latitude =  [NSString stringWithFormat:@"%f",p.location.latitude];
        self.dataHandler.longtitude =[NSString stringWithFormat:@"%f", p.location.longitude];
        
        
        
        
    }
    
    
    
    Reg3ViewController *reg3 = [[Reg3ViewController alloc]initWithNibName:nil bundle:nil];
    
    //保存数据
    self.dataHandler.name = self.textName.text;
    self.dataHandler.shen = self.stateValue;
    self.dataHandler.shi = self.cityValue;
    self.dataHandler.qu = self.districtValue;
    self.dataHandler.shichang = self.textSC.text;
    self.dataHandler.dizhi = self.textDZ.text;
    self.dataHandler.fanwei = self.textSHFW.text;
    self.dataHandler.jiage = self.textQSJG.text;
    
    
    
    
    
    
    [self presentViewController:reg3 animated:YES completion:nil];
    
    

    
}








-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    return 50;

}





-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell11";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell== nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.textColor = [UIColor grayColor];
        cell.textLabel.font = [UIFont systemFontOfSize:16];
        
    }


    if (indexPath.row == 0) {
        
        cell.textLabel.text = @"批发商名称";
        
        if(self.textName == nil)
        {
        
            self.textName = [[UITextField alloc]initWithFrame:CGRectMake(105, 0, ViewWidth -105, 50)];
            self.textName.textColor = [UIColor grayColor];
            self.textName.font = [UIFont systemFontOfSize:16];
            self.textName.delegate = self;
            self.textName.placeholder = @"请输入名称";
            self.textName.tag = 11;
            self.textName.textColor = [UIColor lightGrayColor];
        }
        self.textName.text = self.textName1;
        [cell addSubview:self.textName];

        
        
    }
    else if (indexPath.row == 1)
    {
    
    cell.textLabel.text = @"批发商电话";
        if (self.textPhone == nil) {
            
            self.textPhone = [[UITextField alloc]initWithFrame:CGRectMake(105, 0, ViewWidth - 105, 50)];
            //            self.textName.backgroundColor = [UIColor greenColor];
            self.textPhone.textColor = [UIColor grayColor];
            self.textPhone.font = [UIFont systemFontOfSize:16];
            self.textPhone.delegate = self;
         

            self.textPhone.placeholder = @"请输入手机号";
            self.textPhone.tag = 12;
            self.textPhone.textColor = [UIColor lightGrayColor];
            
    
            self.textPhone.keyboardType = UIKeyboardTypePhonePad;
            
            
            
            
        }
        
        self.textPhone.text = self.textPhone1;
           [cell addSubview:self.textPhone];
    
    }
    else if (indexPath.row == 2)
    {
    
    cell.textLabel.text = @"批发商地区";
        if (self.textDQ == nil) {
            self.textDQ = [[UITextField alloc]initWithFrame:CGRectMake(105, 0, ViewWidth- 105, 50)];
            //            self.textName.backgroundColor = [UIColor greenColor];
            self.textDQ.textColor = [UIColor grayColor];
            self.textDQ.font = [UIFont systemFontOfSize:16];
            self.textDQ.delegate = self;
            self.textDQ.placeholder = @"请选择批发商地区";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

            self.textDQ.tag = 13;
            self.textDQ.enabled = NO;
            self.textDQ.textColor = [UIColor lightGrayColor];

        }
        
        self.textDQ.text = self.textDQ1;
        [cell addSubview:self.textDQ];

    
    }
    else if (indexPath.row == 3)
    {
    
    cell.textLabel.text = @"所 属 市 场";
        if (self.textSC == nil) {
            
            self.textSC = [[UITextField alloc]initWithFrame:CGRectMake(105, 0, ViewWidth -105, 50)];
            //            self.textName.backgroundColor = [UIColor greenColor];
            self.textSC.textColor = [UIColor grayColor];
            self.textSC.font = [UIFont systemFontOfSize:14];
            self.textSC.delegate = self;
            self.textSC.placeholder = @"请选择市场";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            
            self.textSC.tag = 14;


            self.textSC.enabled = NO;
            self.textSC.textColor = [UIColor lightGrayColor];
            
            
        }
        
        self.textSC.text = self.textSC1;
        [cell addSubview:self.textSC];
    
    }
    else if (indexPath.row == 4)
    {
    cell.textLabel.text = @"具 体 地 址";
        if (self.textDZ == nil) {
            
            self.textDZ = [[UITextField alloc]initWithFrame:CGRectMake(105, 0, ViewWidth- 105, 50)];
            self.textDZ.textColor = [UIColor grayColor];
            self.textDZ.font = [UIFont systemFontOfSize:16];
            self.textDZ.delegate = self;
            self.textDZ.placeholder = @"请输入具体地址";
            self.textDZ.tag = 15;
            self.textDZ.textColor = [UIColor lightGrayColor];
            
        }
        self.textDZ.text = self.textDZ1;
        [cell addSubview:self.textDZ];

    
    
    }
    else if (indexPath.row == 5)
    {
    
    cell.textLabel.text = @"送 货 范 围";
        if (self.textSHFW == nil) {
            
            self.textSHFW = [[UITextField alloc]initWithFrame:CGRectMake(105, 0, ViewWidth -105, 50)];
            self.textSHFW.textColor = [UIColor grayColor];
            self.textSHFW.font = [UIFont systemFontOfSize:16];
            self.textSHFW.delegate = self;
            self.textSHFW.placeholder = @"请输入送货范围 如：10";
            
            self.textSHFW.tag = 16;
            self.textSHFW.textColor = [UIColor lightGrayColor];
            self.textSHFW.keyboardType = UIKeyboardTypeDefault;
            
            //添加公里
//            UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(ViewWidth-40, 0, 40, 50)];
//            lbl.text = @"公里";
//            lbl.font = [UIFont systemFontOfSize:16];
//            lbl.textColor = [UIColor grayColor];
//            [cell addSubview:lbl];
            
        }
        self.textSHFW.text = self.textSHFW1;
        [cell addSubview:self.textSHFW];

    }
    else if (indexPath.row == 6)
    {
    
    cell.textLabel.text = @"起 送 价 格";
        
        
        if (self.textQSJG == nil) {
            
            self.textQSJG = [[UITextField alloc]initWithFrame:CGRectMake(105, 0, ViewWidth -105, 50)];
            self.textQSJG.textColor = [UIColor grayColor];
            self.textQSJG.font = [UIFont systemFontOfSize:16];
            self.textQSJG.delegate = self;
            self.textQSJG.placeholder = @"请填写起送价格 如：5";
            self.textQSJG.tag = 17;
            self.textQSJG.textColor = [UIColor lightGrayColor];
            self.textQSJG.keyboardType = UIKeyboardTypePhonePad;

            
            //添加公里
            self.lblp = [[UILabel alloc]initWithFrame:CGRectMake(ViewWidth-30, 0, 30, 50)];
            self.lblp.text = @"元";
            self.lblp.textColor = [UIColor grayColor];
            self.lblp.font = [UIFont systemFontOfSize:16];
       

        }
        
        self.textQSJG.text = self.textQSJG1;
        [cell addSubview:self.textQSJG];
        [cell addSubview:self.lblp];
        
  

        
    
    }
    else if (indexPath.row == 7)
    {
    
    cell.textLabel.text = @"运 费 规 则";
        
        
        if (self.textYFGZ ==nil) {
            self.textYFGZ = [[UITextField alloc]initWithFrame:CGRectMake(105, 0, ViewWidth -105, 50)];
            self.textYFGZ.textColor = [UIColor grayColor];
            self.textYFGZ.font = [UIFont systemFontOfSize:16];
            self.textYFGZ.delegate = self;


            
            
            self.textYFGZ.placeholder = @"未设置";
            self.textYFGZ.tag = 18;
            self.textYFGZ.enabled = NO;
            self.textYFGZ.textColor = [UIColor lightGrayColor];

        }
        self.textYFGZ.text = self.textYFGZ1;
        [cell addSubview:self.textYFGZ];
         cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    }
    return cell;


}




-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{


    if (indexPath.row == 2) {
        
        if (self.orderMskView2 == nil)
        {
            
            self.orderMskView2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ViewWidth, ViewHeight)];
            self.orderMskView2.backgroundColor = [UIColor clearColor];
            [self.view addSubview:self.orderMskView2];
            
            
            
            //收回pickView操作
            UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pickViewHide:)];
            
            //设置成NO便是当前空间响应后会传播到其他控件上，默认为YES
            tapGes.cancelsTouchesInView = NO;
            [self.orderMskView2 addGestureRecognizer:tapGes];
            
        }

        
        
        if (self.locatePicker == nil) {
            
            self.locatePicker = [[HZAreaPickerView alloc]initWithStyle:HZAreaPickerWithStateAndCityAndDistrict delegate:self];
            
            if (ViewHeight  == 480.0) {
                
                
                 [self.locatePicker showInView:self.orderMskView2];
            }
            
            else
            {
            
            self.locatePicker.frame = CGRectMake(0, (ViewHeight-64) *0.7, ViewWidth, (ViewHeight-64)*0.3);
            [self.locatePicker showInView:self.orderMskView2];
                
            }
            
            
            
           
            
        }
        self.orderMskView2.hidden = NO;
        self.locatePicker.hidden = NO;

        
        
    }

    
    
    else if (indexPath.row == 3)
    {
    
    
        
        
        
        //首先判断是否进行了城市的选择
        if (self.textDQ.text.length == 0) {
            
            [self.view makeToast:@"请先选择批发商地区"];
            return;
        }
        
        //获得城市信息。获得批发商的商场

        
        
        [self sendAPI];
        
        
        
        
    
    }
    else if (indexPath.row == 7)
    {
    
        TransRuleViewController *trans = [[TransRuleViewController alloc]initWithNibName: nil bundle:nil];
        
        trans.block = ^(NSArray *message)
        {
            self.backArray = message;
            
            self.dataHandler.yunfeiArray = [self.backArray copy];
        };
        
        [self presentViewController:trans animated:YES completion:nil];
        
    
    
    }

}




#pragma mark 取消地址pickView的现实操作
-(void)pickViewHide:(UITapGestureRecognizer *)tap
{
    
    
    self.orderMskView2.hidden = YES;
    self.locatePicker.hidden = YES;
    
}




#pragma mark  - HZAreaPicker delegate
-(void)pickerDidChaneStatus:(HZAreaPickerView *)picker
{
    if (picker.pickerStyle == HZAreaPickerWithStateAndCityAndDistrict) {
        //传递省市到服务器上
        self.areaValue = [NSString stringWithFormat:@"%@ %@ %@", picker.locate.state, picker.locate.city, picker.locate.district];
      
        
        self.textDQ1 = self.areaValue;
      
        self.stateValue = picker.locate.state;
        self.cityValue = picker.locate.city;
        self.districtValue = picker.locate.district;
        
        
        //判断是否在北京，上海，天津，重庆，海南这些地方，需要重新设置省市区
        
        if ([picker.locate.state isEqualToString:@"北京市"] || [picker.locate.state isEqualToString:@"上海市"] || [picker.locate.state isEqualToString:@"重庆市"] ||  [picker.locate.state isEqualToString:@"天津市"]) {
            
            
            self.stateValue = picker.locate.state;
            self.cityValue = picker.locate.state;
            self.districtValue = picker.locate.city;
            
        }
        
//        NSLog(@"hhhhhhiiihihih  %@  %@  %@",self.stateValue,self.cityValue,self.districtValue);
        
        
        //产地重新赋值
        self.textDQ.text = self.textDQ1;
        
        
        if (self.list.count != 0) {
       
            [self.list removeAllObjects];
            
            
            self.textSC.text = @"";
            self.textSC1 = @"";
            
        }
    
        

        
        [self.tableView reloadData];
        
        
    }
    
    
    
}



#pragma mark 上移键盘操作
- (void)textFieldDidBeginEditing:(UITextField *)textField
{

    if (textField == self.textDZ || textField == self.textSHFW || textField == self.textQSJG  ) {
        //上移键盘操作
        
        
        //伸缩表格
        [UIView animateWithDuration:0.25 animations:^{
            if (self.view.y == 0) {
                self.view.y = -140;
            }
        }completion:^(BOOL finished){

            
        }];
    }




}





//开始编辑的时候收回数字键盘操作
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    
    
    
    
    if (textField == self.textPhone || textField == self.textSHFW || textField == self.textQSJG  )
    {
        
        
        if (self.numberView == nil) {
            
            self.numberView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ViewWidth, ViewHeight-64)];
            self.numberView.alpha = 0.2;
            self.numberView.backgroundColor = [UIColor whiteColor];
            [self.view addSubview:self.numberView];
            
            
        }
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Tapped2:)];
        
        [self.numberView addGestureRecognizer:tap];
        
        
        
        
        
        
        
        
        return YES;
        
    }
    
    
    return YES;
    
    
}




#pragma mark 如果没有没有doneButton的产生就收回就点击空白收回键盘，收回键盘操作
-(void)Tapped2:(UITapGestureRecognizer*)gestureRecognizer
{
    
    
    
    //伸缩表格
    [UIView animateWithDuration:0.25 animations:^{
        if (self.view.y == -140) {
            self.view.y = 0;
            
            
        }
    }completion:^(BOOL finished){
        
        
    }];
    
    
    [self.numberView removeFromSuperview];
    self.numberView = nil;
    
    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];//关闭键盘
    
    
    
}






#pragma mark 进行pickView的设置

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{


    
    if (pickerView == self.pickView2) {
        
        return 1;

    }
    else
    {
    
        return 1;
    
    }



}



//指定pickView中每一列的个数
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    
    
    if (pickerView == self.pickView2) {

       return self.list.count;
    }
    else
    {
    
        return 1;
    }
    
}



-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
    
    return 30;
    
}



#pragma mark pickViewDelegate协议方法
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component

{

    if (pickerView == self.pickView2) {
   

    NSString *str = [NSString stringWithFormat:@"%@",[self.list objectAtIndex:row]];
    return str;
    
    }
    else
    {
    return @"";
    }

}


- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    
    if (pickerView == self.pickView2) {

        self.textSC1 = [self.list objectAtIndex:row];
        self.textSC.text = self.textSC1;
        
    }
   
}








#pragma mark textField进行end操作记住内容
-(void)textFieldDidEndEditing:(UITextField *)textField
{

    if (textField.tag == 11)
    {
        
        self.textName1 = self.textName.text;
    }

    else if (textField.tag == 12)
    {
    
        self.textPhone1 = self.textPhone.text;
    
    }
    else if (textField.tag == 13)
    {
    
    
        self.textDQ1 = self.textDQ.text;
    
    }
    
    else if (textField.tag == 14)
    {
    
        self.textSC1 = self.textSC.text;
    
    }
    else if (textField.tag == 15)
    {
    
        self.textDZ1 = self.textDZ.text;
    
    }
    else if (textField.tag == 16)
    {
    
        self.textSHFW1 = self.textSHFW.text;
    
    }
    else if (textField.tag == 17)
    {
    
        self.textQSJG1 = self.textQSJG.text;
    
    }
    else
        
    {
        self.textYFGZ1 = self.textYFGZ.text;
    }
    
    
    [UIView animateWithDuration:0.3 animations:^{
        if (self.view.y == -140) {
            self.view.y = 0;
            
            
        }
    }completion:^(BOOL finished){
        
        
    }];
    

    

}



-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    
    [textField resignFirstResponder];
    //伸缩表格
    [UIView animateWithDuration:0.25 animations:^{
        if (self.view.y == -140) {
            self.view.y = 0;
            
            
        }
    }completion:^(BOOL finished){
        
        
    }];
    

    return YES;
    
}
@end
